package com.start.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.admin.entity.StartSysNoticeBrowseEntity;
import com.start.admin.service.StartSysNoticeBrowseService;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.core.annotations.RegisterMenu;
import com.start.core.annotations.RegisterPermission;
import com.start.core.annotations.StartLog;
import com.start.security.annotations.DataPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 系统通知公告浏览记录
 *
 * @author gxl
 * @email ${email}
 * @date 2021-02-22 17:25:23
 */
@RestController
@RequestMapping("/start/sys/sysNoticeBrowse")
@RegisterMenu(value = "通知公告浏览记录", systemCode = "sys:SysNoticeBrowse", component = "views/sys/sysNotice/sysNoticeBrowse", path = "/sysNoticeBrowse/index")
public class StartSysNoticeBrowseController {
    private static final String LOG_TITLE = "通知公告浏览记录";

    @Autowired
    private StartSysNoticeBrowseService startSysNoticeBrowseService;

    /**
     * 列表
     */
    @GetMapping("/page")
    @DataPermission("sys/sysNoticeBrowse/list")
    public Result<?> list(Page<StartSysNoticeBrowseEntity> page, StartSysNoticeBrowseEntity entity) {
        QueryWrapper<StartSysNoticeBrowseEntity> queryWrapper = DataQueryConstructor.createEntity(entity);
        return Result.ok(startSysNoticeBrowseService.page(page, queryWrapper));
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @StartLog(value = LOG_TITLE, action = "查询")
    @PreAuthorize("@pas.hasPermission('sys:sysNoticeBrowse:info')")
    @RegisterPermission(value = "sys:sysNoticeBrowse:info", name = "查看")
    public Result<?> info(@PathVariable("id") String id) {
        return Result.ok(startSysNoticeBrowseService.getById(id));
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    @StartLog(value = LOG_TITLE, action = "添加")
    @PreAuthorize("@pas.hasPermission('sys:sysNoticeBrowse:add')")
    @RegisterPermission(value = "sys:sysNoticeBrowse:add", name = "添加")
    public Result<?> save(@RequestBody StartSysNoticeBrowseEntity sysNoticeBrowse) {
        startSysNoticeBrowseService.save(sysNoticeBrowse);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/updateById")
    @StartLog(value = LOG_TITLE, action = "修改")
    @PreAuthorize("@pas.hasPermission('sys:sysNoticeBrowse:edit')")
    @RegisterPermission(value = "sys:sysNoticeBrowse:edit", name = "修改")
    public Result<?> update(@RequestBody StartSysNoticeBrowseEntity sysNoticeBrowse) {
        startSysNoticeBrowseService.updateById(sysNoticeBrowse);
        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteById/{id}")
    @StartLog(value = LOG_TITLE, action = "删除")
    @PreAuthorize("@pas.hasPermission('sys:sysNoticeBrowse:delete')")
    @RegisterPermission(value = "sys:sysNoticeBrowse:delete", name = "删除")
    public Result<?> delete(@PathVariable("id") String id) {
        startSysNoticeBrowseService.removeById(id);
        return Result.ok();
    }

}
